/*
 *  Copyright 2001-2004 The Apache Software Foundation
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package ar.uba.fi.posgrado.common.model;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

/**
 * Rol de usuarios.<br>
 * 
 * @author nicolas.gonzalez
 */
@Entity
@Table(name = "ROL")
@SuppressWarnings("serial")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class Role implements Serializable {

	@Id
	@Column(name = "NOMBRE_ROL", length = 20, unique = true, updatable = false)
	private String name;

	@Column(name = "DESCRIPCION", length = 45)
	private String description;

	public Role() {

	}

	@Override
	public String toString() {
		return ToStringBuilder.reflectionToString(this,
				ToStringStyle.SIMPLE_STYLE);
	}

	@Override
	public int hashCode() {
		return HashCodeBuilder.reflectionHashCode(this,
				new String[] { "description" });
	}

	@Override
	public boolean equals(final Object other) {
		return EqualsBuilder.reflectionEquals(this, other,
				new String[] { "description" });
	}

	/**
	 * @return the name
	 */
	public String getName() {
		return this.name;
	}

	/**
	 * @param name
	 *            the name to set
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * @return the description
	 */
	public String getDescription() {
		return this.description;
	}

	/**
	 * @param description
	 *            the description to set
	 */
	public void setDescription(String description) {
		this.description = description;
	}

	/**
	 * Rol MINIMO de la aplicacion.<br>
	 * Todos los usuarios necesitan como minimo tener este rol asignado.<br>
	 * Este es el motivo x el cual esta hardcoded.<br>
	 * 
	 * @return
	 */
	public static Role getNecessaryRole() {
		Role response = new Role();
		response.setDescription("Rol minimo que se debe poseer");
		response.setName("posgrado");

		return response;
	}

	/**
	 * Devuelve un rol que corresponde a un Ente que dicta cursos
	 * 
	 * @return un rol que corresponde a un Ente que dicta cursos
	 */
	public static Role getBodyRole() {
		Role bodyRole = new Role();
		bodyRole.setName("ente");
		return bodyRole;
	}

}
